/*
 * 原型链继承 子类的原型指向父类的实例
 * function Parent() {
 *   this.property = true
 *   this.list = []
 * }
 * Parent.prototype.getProperty = function() {
 *   return this.property
 * }
 * function Children() {
 *
 *
 *}
 *
 *
 * Children.prototype.getProperty = function() {
 *   return this.property
 * }
 * Children.prototype = Object.create(Parent.prototype)
 * const Children1 = new Children()
 * const Children2 = new Children()
 * Children1.list.push(1)
 * Children1.property = 2
 * Children2.property = 3
 * console.log(Children1.list)
 * console.log(Children2.toString())
 */

/*
 * 构造函数继承 子类的构造函数调用父类
 * function Parent() {
 *   this.list = ['1']
 *   this.property = true
 *   this.getProperty = function() {
 *     return this.property
 *   }
 * }
 * function Children() {
 *   Parent.call(this)
 * }
 * const Children1 = new Children()
 * const Children2 = new Children()
 * Children1.list.push('2')
 * Children2.list.push('3')
 * console.log(Children1.getProperty())
 * console.log(Children1.list)
 * console.log(Children2.list)
 */
/*
 * 组合继承 将原型链继承与构造函数继承合在一起
 * function Parent() {
 *   this.list = ['1']
 *   this.property = true
 * }
 * Parent.prototype.getProperty = function() {
 *   return this.property
 * }
 * function Children() {
 *   Parent.call(this)
 * }
 * Children.prototype = new Parent()
 * const Children1 = new Children()
 * const Children2 = new Children()
 * Children1.list.push('2')
 * Children2.list.push('3')
 * console.log(Children1.getProperty())
 * console.log(Children1.list)
 * console.log(Children2.list)
 */
// 寄生组合继承
function Parent() {
  this.list = ['1']
  this.property = true
}
Parent.prototype.getProperty = function() {
  return this.property
}
function Children() {
  Parent.call(this)
}
Children.prototype = Object.create(Parent.prototype)// 创建父类原型的一个副本并赋值给子类的原型
Children.prototype.constructor = Children// 弥补因重写原型而失去的默认的constructor 属性